package com.ssm.service.impl;

import com.ssm.dao.TeacherMapper;
import com.ssm.entity.Course;
import com.ssm.entity.Teacher;
import com.ssm.service.TeacherService;
import org.apache.ibatis.transaction.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Lenovo on 2019-10-8.
 */
//@Service
public class TeacherServiceImpl  {
    @Autowired
    private DataSource dataSource;

    public DataSource getDataSource() {
        return dataSource;
    }
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
    public void delete(int id){
        try {
            Connection connection=dataSource.getConnection();
            String sql="delete from teacher where id=?";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setInt(1,id);
            ps.execute();
            if(id==1)throw new RuntimeException("rollback test") ;
            else
                connection.commit();

        }  catch (SQLException e) {
            e.printStackTrace();
        }
    }
  }
